package cn.itcast.mq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;

/**
 * The type Fanout config.
 * 交换机创建配置类,测试高级特性，不加入该类的配置
 * @author wwk
 */
//@Configuration
public class FanoutConfig {
    /**
     * Fanout exchange fanout exchange.
     * 创建一个Fanout交换机，交换机名字是itcast.fanout
     * @return the fanout exchange
     */
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("itcast.fanout");
    }

    /**
     * Fanout queue 1 queue.
     *  创建队列 fanout.queue1
     * @return the queue
     */
    @Bean
    public Queue fanoutQueue1(){
        return new Queue("fanout.queue1");
    }

    /**
     * Fanout binding 1 binding.
     *  绑定队列1到交换机
     * @param fanoutQueue1   the fanout queue 1
     * @param fanoutExchange the fanout exchange
     * @return the binding
     */
    @Bean
    public Binding fanoutBinding1(Queue fanoutQueue1, FanoutExchange fanoutExchange){
        return BindingBuilder
                .bind(fanoutQueue1)
                .to(fanoutExchange);
    }

    /**
     * Fanout queue 2 queue.
     *  fanout.queue2
     * @return the queue
     */
    @Bean
    public Queue fanoutQueue2(){
        return new Queue("fanout.queue2");
    }

    /**
     * Fanout binding 2 binding.
     *  绑定队列2到交换机
     * @param fanoutQueue2   the fanout queue 2
     * @param fanoutExchange the fanout exchange
     * @return the binding
     */
    @Bean
    public Binding fanoutBinding2(Queue fanoutQueue2, FanoutExchange fanoutExchange){
        return BindingBuilder
                .bind(fanoutQueue2)
                .to(fanoutExchange);
    }

    /**
     * Object queue queue.
     *
     * @return the queue
     */
    @Bean
    public Queue objectQueue(){
        return new Queue("object.queue");
    }
}
